package com.cskaoyan.controller;


import com.cskaoyan.bean.GrouponRules;
import com.cskaoyan.bean.vo.AdminAdForListDataBean;
import com.cskaoyan.bean.vo.AdminGrouponForListRecordVo;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.AdminGrouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/groupon")
public class AdminGrouponController {

    @Autowired
    AdminGrouponService grouponService;

    @RequestMapping("list")
    public BaseRespVo list(Integer page, Integer limit, String sort, String order, Integer goodsId) {
        AdminAdForListDataBean<GrouponRules> result = grouponService.queryGrouponRules(page, limit, sort, order, goodsId);
        return BaseRespVo.ok(result);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody GrouponRules rules) {
        Integer result = grouponService.addGrouponRules(rules);
        return result == 200 ? BaseRespVo.ok() : BaseRespVo.fail("参数值不正确");
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody GrouponRules rules) {
        Integer result = grouponService.updateGrouponRules(rules);
        return result == 200 ? BaseRespVo.ok() : BaseRespVo.fail("参数值不正确");
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody GrouponRules rules) {
        Integer result = grouponService.deleteGrouponRules(rules);
        return result == 200 ? BaseRespVo.ok() : BaseRespVo.fail();
    }

    @RequestMapping("listRecord")
    public BaseRespVo listRecord(Integer page, Integer limit, String sort, String order, Integer goodsId) {
        AdminAdForListDataBean<AdminGrouponForListRecordVo> result = grouponService.listRecord(page, limit, sort, order, goodsId);
        return BaseRespVo.ok(result);
    }
}
